tinymce_js = {
	d : {
		root : "/",
		end : 0
	},

    tinymce_initd : {
        theme_advanced_buttons1 : "bullist,numlist,outdent,indent,separator,justifyleft,justifycenter,|,undo,redo,|separator,link,unlink,image,separator,bold,italic,strikethrough,separator,sub,sup,forecolor,backcolor,separator,code,pasteword,genx",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        dialog_type : "modal",
        theme_advanced_resize_horizontal : false,
        entity_encoding : "numeric",
        force_p_newlines : true,
        force_br_newlines : false,
        convert_newlines_to_brs : false,
        relative_urls : false,
        remove_script_host : false,
        verify_html : false,
        auto_reset_designmode : true,
        remove_linebreaks : false,
        theme_advanced_resizing : true,
        mode : "textareas",
        theme : "advanced",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_path_location : "bottom",
        plugins : "inlinepopups,paste",
		setup : function(editor) {
			tinymce_js.e_editor = editor;
			tinymce_js.e_editor.addButton(
				'genx',
				{
					title : 'GenX',
					image : 'http://archgfx.net/aspnet_client/tag-ltblue.gif',
					onclick : tinymce_js.ongenx_start
				}
			);
		},
        content_css : "/resources/tinymce.css"
    },

	e_editor : null,

	first : true,
	e_body : null,
	e_genx : null,
	e_popup : null,

	scrubdir : function(dir) {
		if (!dir || dir.length == 0) {
			dir = "";
		} else if (dir.charAt(dir.length - 1) != '/') {
			dir = dir + "/";
		}

		return	dir;
	},

	set_root : function(root) {
		tinymce_js.d.root = tinymce_js.scrubdir(root);
		tinymce_js.tinymce_initd.content_css = tinymce_js.d.root + "/resources/tinymce.css";
	},

	onload : function() {
		tinymce_js.e_body = document.getElementById('id_body');
		tinymce_js.e_genx = document.getElementById('id_genx');
	},

	ongenx_start : function() {
		if (!tinymce_js.e_editor) {
			tinymce_js.e_editor = tinyMCE.activeEditor;
		}

		tinymce_js.e_popup = tinymce_js.e_editor.windowManager.open({
			title : "GenX",
			url : tinymce_js.d.root + "?callbacks=tinymce_js.callbacks&search=" + tinymce_js.e_editor.selection.getContent(),
			dialog_type : "modal",
			width : 600,
			height : 450,
			inline : 1
		});
	},

	t_bookmark : null,

	callbacks : {
		html : function(html) {
			tinymce_js.t_bookmark = tinymce_js.e_editor.selection.getBookmark();
			tinymce_js.e_editor.selection.setContent(html, {format : 'raw'});
		},

		gencard : function(html) {
			tinymce_js.e_editor.setContent(tinymce_js.e_editor.getContent() + html);
		},
	
		_close : function() {
			if (tinymce_js.t_bookmark) {
				tinymce_js.e_editor.selection.moveToBookmark(tinymce_js.t_bookmark);
			}

			tinymce_js.e_editor.windowManager.close(null, tinymce_js.e_popup.id);
		},

		end : 0
	},

	end : 0
};
